tongfusoft.myFavorite = function() {
}

tongfusoft.myFavorite.prototype = {

		myFavoriteList : function(pageIndex,pageSize,query) {
	
		
		common.post('myFavorite/query',{"pageIndex":pageIndex,"pageSize":pageSize,"query":query},function(data){
			
			var docListHtml="<tr><td>"
			$.each(data.list,function(index,item){
				
	
				docListHtml=docListHtml+'<div class="media-box">';
				docListHtml=docListHtml+'<a href="#" docname="'+item.docName+'" onclick="new tongfusoft.myFavorite().detailFavorite(this)" class="pull-left">';
				docListHtml=docListHtml+'<img src="'+common.getContextPath('img/dc/'+item.docIcon)+'" alt="" class="media-box-object img-responsive img-rounded thumb64">';
				docListHtml=docListHtml+'</a>';
				docListHtml=docListHtml+'<div class="media-box-body">';
				
				//操作按钮
				docListHtml=docListHtml+'<div class="pull-right">';
				docListHtml=docListHtml+'<button type="button" docname="'+item.docName+'"  class="btn btn-sm btn-default  icon-list detailBtn" onclick="new tongfusoft.myFavorite().detailFavorite(this)"></button>'
				docListHtml=docListHtml+'<button type="button" docName="'+item.docName+'"  class="btn btn-sm btn-default fa fa-trash delBtn" onclick="new tongfusoft.myFavorite().del(this)"></button>';
				//docListHtml=docListHtml+'<button type="button"  class="btn btn-sm btn-default fa fa-trash"></button>';
				docListHtml=docListHtml+'</div>';
				
				
				docListHtml=docListHtml+'<h4 class="media-box-heading">'+item.docTitle+'</h4>';
				docListHtml=docListHtml+'<small title="'+item.docSummary+'" class="text-muted">'+item.docSummary.substr(0,50)+"....." +'</small>';
				docListHtml=docListHtml+'<p>';
				
				docListHtml=docListHtml+'<em class="fa fa-user mr-sm"> </em><span class="mr">'+item.docAuthor+'</span><em class="fa fa-building mr-sm"> </em><span>'+item.lastUpdDate+'</span>';
				docListHtml=docListHtml+'<span class="mr"></span><a href="'+common.getContextPath('download/'+item.docName)+'" target="_blank" ><em class="fa fa-download mr"></em></a>';
				docListHtml=docListHtml+'</p>';
				docListHtml=docListHtml+'</div>';
				docListHtml=docListHtml+' </div>';
				
				
			});
			
			docListHtml=docListHtml+'</td></tr>';
			$("#myFavoriteListTable").html(docListHtml);
			new tongfusoft.myFavorite().pageing(data);
		});
	},
	
	pageing:function(data){
		
		$('#myFavoriteListPage').jqPaginator({
		    totalPages: data.pages==0?1:data.pages,
		    visiblePages: 5,
		    currentPage: 1,
		    pageSize:data.pageSize,
		    first: '',
	        prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',
	        next: '<li class="next"><a href="javascript:;">下一页</a></li>',
	        last: '',
	        page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
		    onPageChange: function (num, type) {
		    	if(type=='change')
		    		new tongfusoft.myFavorite().myFavoriteList(num,data.pageSize);
		    }
		});
	},
	
	// 删除字典分类
	del : function(obj) {
	
		swal({
			title : "是否确认?",
			text : "",
			type : "warning",
			showCancelButton : true,
			confirmButtonColor : "#DD6B55",
			confirmButtonText : "删除",
			cancelButtonText : "取消",
			closeOnConfirm : true
		}, function() {
			common.ajaxSubmitOnSuccess({
				"docName" : $(obj).attr("docName")
			}, 'myFavorite/del', function(data) {

				if (data.state == 'success') {
					window.location.reload();
				}

			}, "del")
		});

	},
	searchBtn:function(){
		
		$("#searchBtn").click(function(){
			$("#queryText").val(JSON.stringify({"fastText":$("#searchText").val()}));
			new tongfusoft.myFavorite().myFavoriteList(1,10,$("#queryText").val());
			
		});
		
	},
	
	detailFavorite : function(obj){
		window.location.href=common.getContextPath('docView/myFavorite/'+$(obj).attr("docName"));
	},
	
}

$(function(){
	
	var obj= new tongfusoft.myFavorite();
	obj.myFavoriteList(1,10,'');
	obj.searchBtn();
})